//			日期
! function() {
	laydate.skin('danlan'); //切换皮肤，请查看skins下面皮肤库
	laydate({
		elem: '#demo'
	}); //绑定元素
}();
autodivheight();

function autodivheight() { //函数：获取尺寸
	//获取浏览器窗口高度
	var winHeight = 0;
	if(window.innerHeight)
		winHeight = window.innerHeight;
	else if((document.body) && (document.body.clientHeight))
		winHeight = document.body.clientHeight;
	//通过深入Document内部对body进行检测，获取浏览器窗口高度
	if(document.documentElement && document.documentElement.clientHeight)
		winHeight = document.documentElement.clientHeight;
	//DIV高度为浏览器窗口的高度

	a = winHeight - 270;
	if(a < 0) {
		a = 0
		$(".pageTool").css("height", a);
		//		$(".pageTool").css("min-height", 410);

	} else {
		$(".pageTool").css("height", a);
		//		$(".pageTool").css("min-height", 410);

	}

	//				document.getElementById("test").style.height = winHeight / 2 + "px";
}
window.onresize = autodivheight; //浏览器窗口发生变化时同时变化DIV高度
//			全体打钩

var param = {
	userId: $.Cookie("userId"),
	session: $.Cookie("session"),
	companyId: $.Cookie("companyId"),
	index: '0',
	page: '10'

}
var index = 0;
$.ajax({
	url: 'apkListByWeb',
	type: 'POST',
	data: param,
	dataType: 'json',
	success: function(data) {
		//			$("#pageTool").empty()
		if(data.errorCode == 0) {
			$.ajax({
				url: 'paramTypeList',
				type: 'POST',
				data: {
					session: $.Cookie("session"),
					userId: $.Cookie("userId"),
					companyId: $.Cookie("companyId"),
					index: 0,
					page: 30

				},
				dataType: 'json',
				success: function(data) {
					if(data.errorCode == 0) {
						$.each(data.result.paramTypeList, function(i, value) {
							if(data.result.paramTypeList[i].type == "ORG_TYPE") {

							} else {
								error_tpl = '<option value="' + data.result.paramTypeList[i].paramValue + '">' + data.result.paramTypeList[i].paramValue + '</option>"'
								$("#pib").append(error_tpl)
							}

						});
						$('#pib')[0].selectedIndex = -1;

					} else if(data.errorCode == -6) {
						alert("登录超时！")
						top.location.href = 'index.jsp';

					} else {
						alert("请重试！")
					}

				},
				error: function(err) {

					alert("连接服务器失败！请重新提交！")
					top.location.href = 'index.jsp';

				}
			});

			$.each(data.result.apkList, function(i, value) {
				if(i % 2 == 0) {
					var error_tpl = '<div class="manage_content_contenta"><div onclick="checkInputA(this)" class="content_input_b" id="' + value.apkFileId + '"><input id="app_' + value.apkFileId + '" value="' + value.appCode + '" style="display:none"><div id="tick_' + value.apkFileId + '" class="tick">√</div></div><div class="manage_content_header_div">' + value.appCode + '</div><div class="manage_content_header_div">' + value.appName + '</div><div class="manage_content_header_div">' + value.appVersion + '</div><div class="manage_content_header_div">' + value.appName + '</div><div class="manage_content_header_div">' + value.appPackageName + '</div><div class="manage_content_header_div">' + value.deviceType + '</div><div class="manage_content_header_div">' + value.detailDesc + '</div><div class="manage_content_header_div">' + value.detailDesc + '</div><div class="manage_content_header_div">' + value.updatedBy + '</div></div>'

				} else {
					var error_tpl = '<div class="manage_content_content"><div onclick="checkInputA(this)" class="content_input_b" id="' + value.apkFileId + '"><input id="app_' + value.apkFileId + '" value="' + value.appCode + '" style="display:none"><div id="tick_' + value.apkFileId + '" class="tick">√</div></div><div class="manage_content_header_div">' + value.appCode + '</div><div class="manage_content_header_div">' + value.appName + '</div><div class="manage_content_header_div">' + value.appVersion + '</div><div class="manage_content_header_div">' + value.appName + '</div><div class="manage_content_header_div">' + value.appPackageName + '</div><div class="manage_content_header_div">' + value.deviceType + '</div><div class="manage_content_header_div">' + value.detailDesc + '</div><div class="manage_content_header_div">' + value.detailDesc + '</div><div class="manage_content_header_div">' + value.updatedBy + '</div></div>'

				}

				$(".pageTool").append(error_tpl)
			});

			$('.pageToola').Paging({
				pagesize: 10,
				count: data.result.size,
				toolbar: true,
				callback: function(page, size, count) {
					index = page - 1;
					param = {
						userId: $.Cookie("userId"),
						session: $.Cookie("session"),
						companyId: $.Cookie("companyId"),
						index: page - 1,
						page: '10',
						appCode: $("#appCode").val()

					}
					$(".pageTool").empty()

					index = page - 1;
					$.ajax({
						url: 'apkListByWeb',
						type: 'POST',
						data: param,
						dataType: 'json',
						success: function(data) {
							if(data.errorCode == 0) {
								$.each(data.result.apkList, function(i, value) {
									var error_tpl = '<div class="manage_content_content"><div onclick="checkInputA(this)" class="content_input_b" id="' + value.apkFileId + '"><input id="app_' + value.apkFileId + '" value="' + value.appCode + '" style="display:none"><div id="tick_' + value.apkFileId + '" class="tick">√</div></div><div class="manage_content_header_div">' + value.appCode + '</div><div class="manage_content_header_div">' + value.appName + '</div><div class="manage_content_header_div">' + value.appVersion + '</div><div class="manage_content_header_div">' + value.appName + '</div><div class="manage_content_header_div">' + value.appPackageName + '</div><div class="manage_content_header_div">' + value.deviceType + '</div><div class="manage_content_header_div">' + value.detailDesc + '</div><div class="manage_content_header_div">' + value.detailDesc + '</div><div class="manage_content_header_div">' + value.updatedBy + '</div></div>'
									$(".pageTool").append(error_tpl)
								});
							} else if(data.errorCode == -6) {
								alert("登录超时！")
								top.location.href = 'index.jsp';
							}
						},
						error: function(err) {

							alert("连接服务器失败！请重新提交！")
							top.location.href = 'index.jsp';

						}
					});

					//					console.log('当前第 ' + page + '页,每页 ' + size + '条,总页数：' + count + '页')
				}
			});

		} else if(data.errorCode == -6) {
			alert("登录超时！")
			top.location.href = 'index.jsp';

		}

	},
	error: function(err) {

		alert("连接服务器失败！请重新提交！")
		top.location.href = 'index.jsp';

	}
});

function checkInput() {
	var tick = $(".tick").css("display");
	console.log(tick)
	if(tick == "none") {
		$(".tick").show();
		console.log("?")
	} else if(tick == "block") {
		$(".tick").hide();
		$(".tick").hide();
		$(".tick_block ").hide();
		console.log("6")
	}
}

//			单独打钩
var tickId = 0;
var tickaId = '';
var somearray = []

function removeByValue(arr, val) {
	for(var i = 0; i < arr.length; i++) {
		if(arr[i] == val) {
			arr.splice(i, 1);
			break;
		}
	}
}
var apkid;
var apkidd = [];

function checkInputA(data) {
	var ticka = "tick_" + data.id;
	apkdd = "app_" + data.id;
	var tickBlock = document.getElementById(ticka);
	apkiddd = document.getElementById(apkdd).value;
	if(tickBlock.style.display == "block") {
		tickBlock.style.display = "none";
		removeByValue(apkidd, apkiddd);
		removeByValue(somearray, data.id);
		apkid = apkidd[0];
		tickId = tickId - 1;
		tickaId = somearray[0];
	} else if(tickBlock.style.display == "" || tickBlock.style.display == "none") {
		tickBlock.style.display = "block";
		removeByValue(somearray, data.id);
		somearray.push(data.id);
		tickaId = somearray[0];
		tickId = tickId + 1;
		removeByValue(apkidd, apkiddd);
		apkidd.push(apkiddd);
		apkid = apkidd[0];
	}
}
//			跳转注册
function manageRegister() {
	window.location.href = 'manageAdd.jsp';
}

function manageamend() {
	if(tickId == 0) {
		alert("请选择要修改的记录")
	} else if(tickId == 2) {
		alert("一次只能修改一条记录！")

	} else if(tickId == 1) {
		sessionStorage.setItem("totalData", tickaId);
		sessionStorage.setItem("index", index);
		window.location.href = 'manageamend.jsp';
	}
}

function managedelect() {
	if(tickId == 0) {
		alert("请选择要删除的记录")
	} else if(tickId == 2) {
		alert("一次只能删除一条记录！")

	} else if(tickId == 1) {
		var param = {
			userId: $.Cookie("userId"),
			session: $.Cookie("session"),
			apkId: tickaId
		}
		$.ajax({
			url: 'deleteApk',
			type: 'POST',
			data: param,
			dataType: 'json',
			success: function(data) {

				if(data.errorCode == 0) {
					alert("删除成功！")
					window.location.href = 'manage.jsp';

				} else if(data.errorCode == -6) {
					alert("登录超时！")
					top.location.href = 'index.jsp';

				}

			},
			error: function(err) {

				alert("连接服务器失败！请重新提交！")
				top.location.href = 'index.jsp';

			}
		});
	}
}

function inquiry() {

	if($("#pib").val() == null) {
		var param = {
			userId: $.Cookie("userId"),
			session: $.Cookie("session"),
			companyId: $.Cookie("companyId"),
			index: '0',
			page: '10',
			appCode: $("#appCode").val(),
		}
	} else {
		var param = {
			userId: $.Cookie("userId"),
			session: $.Cookie("session"),
			companyId: $.Cookie("companyId"),
			index: '0',
			page: '10',
			appCode: $("#appCode").val(),
			dvcType: $("#pib").val()
		}
	}

	$.ajax({
		url: 'apkListByWeb',
		type: 'POST',
		data: param,
		dataType: 'json',
		success: function(data) {
			$(".pageTool").html("")
			if(data.errorCode == 0) {
				$.each(data.result.apkList, function(i, value) {
					if(i % 2 == 0) {
						var error_tpl = '<div class="manage_content_contenta"><div onclick="checkInputA(this)" class="content_input_b" id="' + value.apkFileId + '"><input id="app_' + value.apkFileId + '" value="' + value.appCode + '" style="display:none"><div id="tick_' + value.apkFileId + '" class="tick">√</div></div><div class="manage_content_header_div">' + value.appCode + '</div><div class="manage_content_header_div">' + value.appName + '</div><div class="manage_content_header_div">' + value.appVersion + '</div><div class="manage_content_header_div">' + value.appName + '</div><div class="manage_content_header_div">' + value.appPackageName + '</div><div class="manage_content_header_div">' + value.deviceType + '</div><div class="manage_content_header_div">' + value.detailDesc + '</div><div class="manage_content_header_div">' + value.detailDesc + '</div><div class="manage_content_header_div">' + value.updatedBy + '</div></div>'
					} else {
						var error_tpl = '<div class="manage_content_content"><div onclick="checkInputA(this)" class="content_input_b" id="' + value.apkFileId + '"><input id="app_' + value.apkFileId + '" value="' + value.appCode + '" style="display:none"><div id="tick_' + value.apkFileId + '" class="tick">√</div></div><div class="manage_content_header_div">' + value.appCode + '</div><div class="manage_content_header_div">' + value.appName + '</div><div class="manage_content_header_div">' + value.appVersion + '</div><div class="manage_content_header_div">' + value.appName + '</div><div class="manage_content_header_div">' + value.appPackageName + '</div><div class="manage_content_header_div">' + value.deviceType + '</div><div class="manage_content_header_div">' + value.detailDesc + '</div><div class="manage_content_header_div">' + value.detailDesc + '</div><div class="manage_content_header_div">' + value.updatedBy + '</div></div>'
					}
					$(".pageTool").append(error_tpl)
				});
			} else if(data.errorCode == -6) {
				alert("登录超时！")
				top.location.href = 'index.jsp';
			}
		},
		error: function(err) {
			alert("连接服务器失败！请重新提交！")
			top.location.href = 'index.jsp';
		}
	});
}

function manageclear() {
	$("#appCode").val("");
	$('#pib')[0].selectedIndex = -1;

}

function managedetails() {

	if(tickId == 0) {
		alert("请选择要查看的记录")
	} else if(tickId == 2) {
		alert("一次只能查看一条记录！")

	} else if(tickId == 1) {
		var param = {
			userId: $.Cookie("userId"),
			session: $.Cookie("session"),
			companyId: $.Cookie("companyId"),
			appCode: apkid,
			index: index,
			page: "10",

		}
		$(".spinner").show();
		$.ajax({
			url: 'apkListByWeb',
			type: 'POST',
			data: param,
			dataType: 'json',
			success: function(data) {
				if(data.errorCode == 0) {
					data.result.apkList[0]
					$(".appCode").text(data.result.apkList[0].appCode);
					$(".appName").text(data.result.apkList[0].appName);
					$(".appVersion").text(data.result.apkList[0].appVersion);
					$(".appPackageName").text(data.result.apkList[0].appPackageName);
					$(".appSize").text(data.result.apkList[0].appSize);
					$(".deviceType").text(data.result.apkList[0].deviceType);
					$(".developer").text(data.result.apkList[0].developer);
					$(".summaryDesc").text(data.result.apkList[0].summaryDesc);
					$(".detailDesc").text(data.result.apkList[0].detailDesc);
					$(".updateDesc").text(data.result.apkList[0].updateDesc);
					$(".updatedBy").text(data.result.apkList[0].updatedBy);
					$(".companyId").text($.Cookie("companyId"));
					$(".spinner").hide();

					$(".tails").show();
					$(".tailsa").show();
					$(".tailsa-content").show();
				} else if(data.errorCode == -6) {
					alert("登录超时！")
					top.location.href = 'index.jsp';

				}

			},
			error: function(err) {

				alert("连接服务器失败！请重新提交！")
				top.location.href = 'index.jsp';

			}
		});
	}
}

$(".tailsa-header-x").click(function() {
	$(".tails").hide();
	$(".tailsa").hide();
});